<template>
  <div>
    <!-- <div class="app-main-title">签约记录</div> -->
    <QueryForm
      v-model="filters"
      :query-form-config="queryFormConfig"
      @handleQuery="getList(1)"
      @clear="clear"
    />
    <el-table
      ref="table"
      v-loading="listLoading"
      :data="list"
      element-loading-text="Loading"
      border
      fit
      :header-row-class-name="'table-header'"
      class="doumee-element-table"
    >
      <el-table-column
        align="center"
        label="团体名称"
        min-width="200"
        prop="teamName"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        label="管理员"
        show-overflow-tooltip
        min-width="200"
        prop="admin"
      />
      <el-table-column
        align="center"
        label="签约类型"
        prop="type"
        min-width="100"
      >
        <template slot-scope="scope">
          {{
            scope.row.type == "1"
              ? "首充"
              : scope.row.type == "2"
                ? "签约"
                : "签约"
          }}
        </template>
      </el-table-column>
      <el-table-column
        align="center"
        label="会员卡类型"
        prop="cardType"
        show-overflow-tooltip
        min-width="200"
      />
      <el-table-column
        align="center"
        label="签约金额"
        prop="amot"
        show-overflow-tooltip
        min-width="100"
      />
      <el-table-column
        align="center"
        label="交易状态"
        prop="status"
        min-width="100"
      >
        <template slot-scope="scope">
          {{
            scope.row.status == "0"
              ? "待支付"
              : scope.row.status == "1"
                ? "正常"
                : scope.row.status == "2"
                  ? "撤销"
                  : "撤销"
          }}
        </template>
      </el-table-column>
      <el-table-column align="center" label="合同" prop="payTime" min-width="120">
        <template slot-scope="scope">
          <span
            class="primaryColor pointer"
            @click="downLoadHt(scope.row.htURL)"
          >点击下载</span>
        </template>
      </el-table-column>
      <el-table-column
        align="center"
        label="签约时间"
        prop="createDate"
        min-width="160"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        label="操作人"
        prop="creator"
        min-width="120"
        show-overflow-tooltip
      />
    </el-table>
    <!-- <div class="flex-cc doumee-pagination">
      <el-pagination
        background
        layout="prev, pager, next"
        :total="totalCount"
        :current-page.sync="pagination.page"
        hide-on-single-page
        @current-change="getList"
      />
    </div> -->
    <Paginations
      :total="totalCount"
      :page="pagination.page"
      @current-change="getList"
      @SizeChange="handleSizeChange"
    />
  </div>
</template>

<script>
import { parseTime } from '@/utils/index'
import { orderListTeam } from '@/api'
import QueryForm from '@/components/QueryForm'
export default {
  name: 'GroupRecord',
  components: {
    QueryForm
  },
  data() {
    return {
      queryFormConfig: {
        formItems: [{
          filed: 'name',
          type: 'input',
          label: '团体名称',
          placeholder: '请输入团体名称',
          clearable: true
        }, {
          filed: 'type',
          type: 'select',
          label: '签约类型',
          placeholder: '请选择签约类型',
          clearable: true,
          options: [
            { value: '1', label: '首充' },
            { value: '2', label: '续签' }
          ]
        }, {
          filed: 'status',
          type: 'select',
          label: '交易状态',
          placeholder: '请选择交易状态',
          clearable: true,
          options: [
            { value: '0', label: '待支付' },
            { value: '1', label: '正常' },
            { value: '2', label: '撤销' }
          ]
        }],
        online: true
      },
      meta: [],
      list: [],
      totalCount: 0,
      filters: {},
      listLoading: true,
      show: false,
      pagination: {
        page: 1,
        rows: 10
      },
      orderId: '',
      form: {},
      rules: {
        price: [
          {
            pattern: /^(([1-9][0-9]*)|(([0]\.\d{1,2}|[1-9][0-9]*\.\d{1,2})))$/,
            required: true,
            message: '请输入正确课时总价(元),最多保留2位小数',
            trigger: 'blur'
          }
        ],
        info: [
          {
            required: true,
            message: '费用由线下退款，请具体描述退课原因',
            trigger: 'blue'
          }
        ]
      }
    }
  },
  created() {
    this.meta = this.$route.meta.buttons || []
    this.getList(1)
  },
  activated() {
    this.$refs.table.doLayout()
  },
  methods: {
    downLoadHt(hturl) {
      if (!hturl) {
        this.$message.warning('暂无合同')
        return
      }
      window.open(hturl, '_blank')
    },
    handleSizeChange(value) {
      this.pagination.rows = value
      this.getList(1)
    },
    // 获取续签记录列表
    getList(page) {
      this.listLoading = true
      const { filters, pagination } = this
      const venueId = sessionStorage.getItem('venueId')
      if (page) {
        pagination.page = page
        this.pagination.page = page
      }
      if (pagination.page === 1) {
        pagination.firstQueryTime = parseTime(new Date())
      }
      orderListTeam({
        pagination,
        param: {
          venueId,
          ...filters
        },
        userId: sessionStorage.getItem('userId')
      })
        .then((res) => {
          this.listLoading = false
          if (res.errorCode === '000000') {
            this.list = res.recordList
            this.totalCount = res.totalCount
          }
        })
        .catch((err) => {
          this.listLoading = false
          console.log(err)
        })
    },
    clear() {
      this.filters = {}
      this.getList(1)
    }
  }
}
</script>
